<template>
	<view class="content">
		<!-- 消息通知 -->
		<u-form :model="formData" ref="uForm" label-align="center" :label-style="labelStyle" :error-type="errorType"
			label-width=180>
			<u-form-item :label="formData.title" class="form-item-top" label-align="left" label-position="top">
				<view class="textarea">{{ formData.content }}</view>
			</u-form-item>
			
			<view class="" style="margin:-10rpx 0 20rpx; text-align: right;">
				<u-button class="copy-btn" type="success" size="mini" @click="copy(formData.content)">点此将通知复制到剪贴板</u-button>
			</view>
			
			<u-form-item label="消息发送时间" class="form-item-top" label-align="left" label-position="top">
				<view class="text">{{ formData._add_time_str }}</view>
			</u-form-item>
		</u-form>
		
		<u-button v-if="formData.case_id" type="primary" plain :loading="loading" @click="pageTo('/pages_case/case/detail?id=' + formData.case_id)">跳转到纠纷详情</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			let formData = {
				title: '',
				content: '',
			}
			return {
				disabled: false,
				loading: false,

				formData, // 咨询

				placeholderStyle: this.$css.placeholderStyle,
				styles: this.$css.styles,
				errorType: this.$css.errorType,
				labelStyle: this.$css.labelStyle,
			}
		},
		onLoad(options) {
			this.init(options);
		},
		methods: {
			// 页面数据初始化函数
			init(options = {}) {
				this.id = options.id;
				if(this.id){
					this.getData();
				}
			},
			pageTo(path){
				this.loading = true;
				vk.navigateTo(path);
			},
			getData(){
				vk.callFunction({
					url: this.$api.NoticeInfo,
					loading: true,
					data: {
						_id: this.id
					},
					success: (res) => {
						console.log(res)
						this.formData = res.item;
						
						if(vk.pubfn.isNull(this.formData.readlog)){
							this.addReadLog();
						}
					}
				})
			},
			addReadLog(){
				vk.callFunction({
					url: this.$api.AddNoticeReadLog,
					loading: true,
					data: {
						notification_id: this.id,
					},
					success: (res) => {
						console.log(res)
					}
				})
			},
			// 复制到剪贴板
			copy(text) {
				uni.setClipboardData({
					data: text, //要被复制的内容
					success: () => { //复制成功的回调函数
						vk.toast('已复制到剪贴板');
					}
				});
			},
		}
	}
</script>